import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core';
import { ICellRendererAngularComp } from '@ag-grid-community/angular';
import {
  deepClone,
  exists, formatNumber, getO,
  getValueUsingField,
  isObject, replaceAll,
} from '../../../utils/utils';
import { SearchService } from '../../../core/services/search.service';
import { SubjectService } from '../../../core/services/events/subject.service';
import { ApesContextMenuService } from '../context-menu/index';
import { ExpressionService } from '@core/services/expression/ExpressionService';
import { DialogInquiryComponent } from '@shared/dialog-inquiry/dialog-inquiry.component';
import { ApesInputFormComponent } from '@shared/apes-input-form/apes-input-form.component';
import { ApesDrawerService } from '@shared/apes/drawer';
import { ApesDrawerCustomGridComponent } from '@shared/ag-grid-ext/drawer-custom/drawer-custom-grid.component';
import { ApesMessageService } from '@shared/apes/message';
import { ReuseTabService } from '@shared/apes/reuse-tab';
import { ActivatedRoute, Router } from '@angular/router';
import { GridConfigService } from '@core/config/grid-config.service';
import { ApiService } from '@core/services/http/api.service';
import { Events } from '@core/services/events/Events';
import { ApesModalService } from '@shared/apes/modal';
import { DrawerInquiryComponent } from '@shared/drawer-inquiry';
import { DrawerVehicleMasterControlComponent } from '@shared/drawer-vehicleMasterControl';
import { Subject } from 'rxjs';
import { toBoolean } from '@shared/apes/core';
import { ApesToolTipBaseComponent } from '@shared/apes/tooltip';
import { DialogMakeInquiryComponent } from '@shared/dialog-make-inquiry';
import { ButtonService } from '@core/services/button.service';

export interface BaseBtnFace {
  btn: any,
  showHidden?: boolean,
  showDisabled?: boolean
  showTooltip?: boolean,
  type?: string
}

@Component({
  selector: 'apes-operating-button',
  template: `
    <div class="apes-operating-button">

      <!--默认按钮-->
      <ng-container *ngIf="!_showHidden">
        <ng-container *ngFor="let btn of buttonList; let i = index;">

          <ng-container *ngIf="btn.link else temp">
            <div class="box-div" (click)="clickOperating(i)">
              {{getDisplayName() || btn.name}}
            </div>
          </ng-container>

          <ng-template #temp>
            <apes-badge apesDot [apesShowDot]="isShowDot(btn)" class="gird-button-badge">

              <button *ngIf="checkShowBtn({btn:btn,showTooltip:false})"
                      style="flex:1 1"
                      class="grid-button"
                      apesType="link" apes-button
                      (click)="clickOperating(i)"
                      [ngStyle]="showBtnStyle(btn)"
                      [apesLoading]="isLoading"
                      [disabled]="btn.disabled">
                <ng-container *ngIf="btn.hasOwnProperty('status')">
                  <div style="display: inline-block;position: relative;
    top: -1px;" [ngSwitch]="checkBtnStatus(btn.status)">
                    <div *ngSwitchCase="'default'">
                      <apes-badge apesColor="#ddd"></apes-badge>
                    </div>
                    <div *ngSwitchCase='"success"'>
                      <apes-badge apesStatus="success"></apes-badge>
                    </div>
                    <div *ngSwitchCase='"error"'>
                      <apes-badge apesStatus="error"></apes-badge>
                    </div>
                    <div *ngSwitchCase='"processing"'>
                      <apes-badge apesStatus="processing"></apes-badge>
                    </div>
                    <div *ngSwitchCase='"warning"'>
                      <apes-badge apesStatus="warning"></apes-badge>
                    </div>
                  </div>
                </ng-container>
                <ng-container *ngIf="!btn.hasOwnProperty('icon')">
                  {{getCustomName(btn)}}
                </ng-container>
                <ng-container *ngIf="btn.hasOwnProperty('icon')">
                  <i apes-icon [ngStyle]="showIconStyle(btn)" [apesType]="btn.icon"
                     [apesTheme]="showBtnIconTheme(btn)"></i>
                </ng-container>
              </button>

              <button *ngIf="checkShowBtn({btn:btn,showTooltip:true})"
                      class="grid-button"
                      style="flex:1 1"
                      apesType="link"
                      apes-button
                      apes-tooltip
                      [apesTooltipTitle]="template1"
                      [ngStyle]="showBtnStyle(btn)"
                      (click)="clickOperating(i)"
                      [apesLoading]="isLoading"
                      [disabled]="btn.disabled">
                {{getCustomName(btn)}}
              </button>
              <ng-template #template1>
                <div [innerHTML]="getTooltipFormatter(btn)"></div>
              </ng-template>

            </apes-badge>
          </ng-template>

        </ng-container>
      </ng-container>

      <!--显示隐藏按钮-->
      <ng-container *ngIf="_showHidden">
        <ng-container *ngFor="let btn of buttonList; let i = index;">

          <div *ngIf="checkShowBtn({btn:btn,showHidden:false})" class="box-div">****</div>

          <button *ngIf="checkShowBtn({btn:btn,showHidden:true,showDisabled:false})"
                  class="grid-button"
                  style="flex:1 1"
                  apesType="link"
                  apes-button
                  apes-tooltip
                  [apesTooltipTitle]="template2"
                  (click)="clickOperating(i)"
                  [apesLoading]="isLoading"
                  [disabled]="btn.disabled">
            {{getCustomName(btn)}}
          </button>

          <div *ngIf="checkShowBtn({btn:btn,showHidden:true,showDisabled:true})"
               apes-tooltip
               [ngClass]="{'apes-operating-Tooltip-button': btn['TooltipTrigger'] == 'click'}"
               [apesTooltipTrigger]="btn.hasOwnProperty('TooltipTrigger')? btn['TooltipTrigger']: 'hover'"
               [apesTooltipTitle]="template2">{{getCustomName(btn)}}</div>
          <ng-template #template2>
            <div [innerHTML]="getTooltipFormatter(btn)"></div>
          </ng-template>

        </ng-container>
      </ng-container>

      <!--更多按钮-->
      <button *ngIf="showMore && showMoreList.length > 0" apes-button apes-popover
              [apesPopoverContent]="contentTemplate" apesPopoverPlacement="rightTop">
        <i apes-icon apesType="ellipsis"></i>
      </button>
      <ng-template #contentTemplate>
        <div class="apes-operating-popover-button">
          <ng-container *ngFor="let btn of showMoreList; let i = index;">

            <button *ngIf="checkShowBtn({btn:btn,type:'showMore'})"
                    apesType="link"
                    class="grid-button"
                    apes-button
                    (click)="clickOperating(i,'showMore')"
                    [disabled]="btn.disabled">
              {{btn.name}}
            </button>
          </ng-container>
        </div>
      </ng-template>

    </div>
  `,
  styles: [`
    .apes-operating-button {
      text-align: center;
      display: flex;
      justify-content: center;
    }

    .apes-operating-popover-button {
      display: flex;
      flex-direction: column;
    }

    .apes-operating-Tooltip-button {
      cursor: pointer;
    }

    .box-div {
      width: 100%;
      height: 100%;
      color: #3693c6;
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
    }

    .box-div:hover {
      color: red;
      cursor: pointer;
    }

    .grid-button {
      /*background: transparent;*/
      /*border-color: transparent;*/
      padding: 0 8px;
    }

    .grid-button[disabled] {
      background: transparent;
      border-color: transparent;
    }
  `],
  // changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RenderOperatingButtonComponent implements ICellRendererAngularComp {
  refresh(params: any): boolean {
    return false;
  }

  _showHidden: boolean = false;
  params: any;
  ctx: any = {};
  apesConfig: any;

  name: any;
  rowIndex: any;
  data: any = {};
  gridName: any = '';
  colKey: any = '';

  domain: any;
  buttonList = [];
  showMoreList = [];
  showMore;
  hideBtnBar: boolean = false;
  showDot: any;
  isLoading: boolean = false;

  // buttonList: any = [{
  //   'id': 'add',                                      // 按钮ID（必填）
  //   'name': '添加',                                   // 按钮名称（必填）
  //   'action': 'dialog',                               // action的模式 dialog or link or（必填）
  //   'hide':'false',                                   // 是否隐藏，支持表达式（可选）
  //   'disabled':'disabled',                            // 是否可编辑，支持表达式（可选）
  //   'api': 'cm.parts.name.findAll',                   // api（必填，删除不用）
  //   'rowSelection': 'single',                         // dialog的选择模式 multiple  or single（可选）
  //   'formId':'cm.product.findProductByServicePlan',   // formId（可选）
  //   'secondaryApi':'fn.service.getPrise',             // 二次查询api（可选）
  //   'uniqueKey':'innerBusinessKey',                   // multiple时唯一键（可选，dialog）
  //   'valueFormatter': 'value.name'                    // multiple时显示（可选，dialog）
  // }];                                                 // xml配置格式

  constructor(
    protected searchService: SearchService,
    protected subject: SubjectService,
    private contextService: ApesContextMenuService,
    private expressionService: ExpressionService,
    protected drawerService: ApesDrawerService,
    private msg: ApesMessageService,
    protected rs: ReuseTabService,
    private router: Router,
    private gridConfigService: GridConfigService,
    protected apiService: ApiService,
    private event: Events,
    private modalService: ApesModalService,
    private buttonService: ButtonService,
    protected cd: ChangeDetectorRef,
  ) {
  }

  multiple: boolean = false;

  agInit(params: any): void {
    this.params = params;
    this.rowIndex = deepClone(this.params.rowIndex);
    if (params.context) {
      this.ctx = params.context;
      this.gridName = this.ctx.gridName;
    }
    this.apesConfig = this.extend(params);
    this.apesConfig = { ...this.apesConfig, ...params['column']['colDef'] };

    if (this.params.hasOwnProperty('colDef')) {
      this.data = this.params.data;
      this.colKey = this.params.colDef.field;
    } else {
      this.data = this.params.node.data;
      this.colKey = this.params['column']['colDef'].field;
    }

    this.showMore = this.apesConfig.showMore;

    if (this.showMore) {
      let list = this.apesConfig.buttonList;
      this.showMoreList = [];
      this.buttonList = [];
      list.map(btn => {
        if (btn.showMore) {
          this.showMoreList.push(btn);
        } else {
          this.buttonList.push(btn);
        }
      });
    } else {
      this.buttonList = this.apesConfig.buttonList;
    }

    if (this.data && this.data.hasOwnProperty('hideBtnBar')) {
      this.hideBtnBar = true;
    }
    if (this.params.column['colDef'].hasOwnProperty('showHidden')) {
      this._showHidden = true;
    }
  }

  extend(data: any) {
    let result = {};
    for (let key in data) {
      let value = data[key];
      if (key === 'context') {
        result['ctx'] = value;
      } else {
        result[key] = value;
      }
    }
    return result;
  }

  getDisplayName() {
    let value = '';
    if (this.data) {
      value = this.data[this.colKey];
      if (this.params.colDef.hasOwnProperty('valueFormatterMeta')) {
        if (value == null) {
          value = '0';
        }
        if (this.params.colDef.valueFormatterMeta == 'currency') {
          value = '￥' + formatNumber(value, 2);
        } else if (this.params.colDef.valueFormatterMeta == 'number') {
          value = formatNumber(value, 2);
        }

      }
      return value;
    } else
      return null;
  }

  getCustomName(btn) {
    if (btn.name.indexOf('\'') == -1) return btn.name;
    let value = deepClone(btn.name);
    value = value.replace(/\'/g, '');

    let name = this.expressionService.evaluate(value, {
      context: this.ctx,
      model: this.ctx['model'],
      data: this.data,
    });

    if (name == null) {
      name = btn.name;
    }

    return name;
  }

  getButtonHide(id: any, type?) {
    let iLen;
    if (type == 'showMore') {
      iLen = this.showMoreList.length;
    } else {
      iLen = this.buttonList.length;
    }
    // let iLen = this.apesConfig.buttonList.length;
    let expression = 'false';
    for (let i = 0; i < iLen; i++) {
      let button;
      if (type == 'showMore') {
        button = this.showMoreList[i];
      } else {
        button = this.buttonList[i];
      }
      if (id == button.id) {
        expression = button.hide || 'false';
        break;
      }
    }
    return !this.expressionService.eval(expression, {
      context: this.ctx,
      model: this.ctx['model'],
      data: this.data,
    });
  }


  clickOperating(i, type?) {
    // console.log(i);
    if (this.hideBtnBar) return;
    let btn;
    if (type == 'showMore') {
      btn = this.showMoreList[i];
    } else {
      btn = this.buttonList[i];
    }
    if (btn.action == 'dialog') {
      this.openDialog(btn);
    } else if (btn.action == 'link') {
      this.openLink(btn);
    } else if (btn.action == 'delete') {
      this.removeRow(btn);
    } else if (btn.action == 'drawer') {
      this.openDrawer(btn);
    } else if (btn.action == 'print') {
      this.openPrint(btn);
    } else if (btn.action == 'confirm') {
      this.openConfirm(btn);
    } else if (btn.action == 'button') {
      this.openButton(btn);
    }
  }

  // 弹框
  openDialog(params) {
    let formId = '';
    let multiple = params.rowSelection === 'multiple' || false;
    let dialog;

    let gridData = '';
    let conditionModel = {};
    if (this.ctx.hasOwnProperty('model')) {
      let model = this.ctx['model'];
      let filterModel = {};
      if (params.hasOwnProperty('filterConditionData')) {
        let filterCondition = JSON.parse(params.filterConditionData.replace(/^"|"$/g, '').replace(/'/g, '"'))
        filterCondition.forEach((key) => {
          filterModel[key] = model[key];
        });
      } else {
        filterModel = model;
      }
      conditionModel = { ...filterModel, node: this.params.node['data'] };
      gridData = this.ctx['model'][this.gridName];
    } else {
      conditionModel = { node: this.params.node['data'] };
    }



    const options = {
      multiple: multiple,
      ...params,
      conditionModel: conditionModel,
      gridData: gridData,
    };
    if (params.hasOwnProperty('formId')) {
      formId = params.formId;
    } else {
      formId = params.api;
    }
    if (params.hasOwnProperty('width')) {
      options['width'] = params.width;
    }

    if (params.hasOwnProperty('custom')) {
      if (params.custom == 'DialogInquiry') {
        dialog = DialogInquiryComponent;
      } else if (params.custom == 'DialogMakeInquiry') {
        dialog = DialogMakeInquiryComponent;
      }
    }
    // 用于判断是否新增行或更新表内数据
    if (params.compile) {
      dialog = ApesInputFormComponent;
    }

    this.searchService.openDialog(formId, options, (result: any) => {
      let callbackBody = this.apesConfig.callback;

      if (result && (result.length > 0 || typeof result == 'object')) {
        let data = {
          data: result,
          rowIndex: this.rowIndex,
          buttonId: params.id,
          multiple: multiple,
        };
        // if (multiple) {
        //
        //   data = { data: result, rowIndex: this.rowIndex };
        // } else {
        //   data = result;
        // }

        this.expressionService.evaluate(callbackBody, {
          context: this.ctx,
          form: this.ctx['form'],
          model: this.ctx['model'],
          data: data,
          value: result,
          event: this.event,
        }, true);
      }
    }, dialog).subscribe();

  }

  // 链接
  openLink(params) {
    let data = this.data;
    let config = deepClone(params.config);
    let callbackBody = this.apesConfig.callback;

    let api = this.expressionService.evaluate(params.api, {
      context: this.ctx,
      model: this.ctx['model'],
      data: this.data,
    });

    let configApi = this.expressionService.evaluate(config.api, {
      context: this.ctx,
      model: this.ctx['model'],
      data: this.data,
    });

    if (api == null) {
      api = params.api;
    }

    if (configApi != null) {
      config.api = configApi;
    }

    let resultData = {};
    if (config.hasOwnProperty('domain')) {
      this.domain = JSON.parse(config['domain']);
      let domainKeys = Object.keys(this.domain);
      domainKeys.forEach(key => {
        resultData[this.domain[key]] = getValueUsingField(this.data, key, true);
      });
    } else if (callbackBody) {
      let node = { ...params };
      resultData = this.expressionService.evaluate(callbackBody, {
        context: this.ctx,
        model: this.ctx['model'],
        data: this.data,
        node: node,
      }, true);
    } else {
      resultData = data;
    }
    if (data.hasOwnProperty('FORM_ID')) {
      api = data['FORM_ID'];
      config.api = data['API'];
    }
    if (api.indexOf('app/') != -1) {
      let href = window.location.href.split('#');
      let h = href[0].split('erp');
      this.event.publish('drawer');
      window.open(h[0] + api, '_blank');
      return;
    }

    this.buttonService.getMenuLog('/' + api, 'link');

    if (params.hasOwnProperty('routerData')) {
      this.switchLink(resultData, api, config);
    } else {
      this.contextService.openContextLink(resultData, api, config);
    }
  }

  // 删除
  removeRow(params) {
    let data = [];
    let rows = this.getRows();
    // console.log(rows);
    let check = true;
    let checkRemove;
    if (params.hasOwnProperty('checkRemove')) {
      checkRemove = params['checkRemove'];
      let msg = this.expressionService.evaluate(checkRemove, {
        value: this.data,
      });
      if (msg) {
        this.msg.error(msg);
        check = false;
      }
    }

    if (check) {
      if (params.hasOwnProperty('associatedNode')) {
        const associatedNode = params['associatedNode'];
        const parentField = this.expressionService.evaluate(params['parentField'], {
          value: this.data,
        });
        if (this.data.hasOwnProperty(associatedNode)) {
          data.push(this.data);
        } else {
          rows.forEach((row) => {
            // console.log(row);
            // if(row.hasOwnProperty(associatedNode)) return;
            // console.log(row[associatedNode]);
            if (row[associatedNode] == parentField) {
              let checkParent = true;
              if (checkRemove) {
                let msg = this.expressionService.evaluate(checkRemove, {
                  value: row,
                });
                if (msg) {
                  this.msg.error(msg);
                  checkParent = false;
                }
              }
              if (checkParent) {
                data.push(row);
              }
            }
          });
          data.push(this.data);
        }
      } else {
        data.push(this.data);
      }

      this.params.api.updateRowData({ remove: data });
      // console.log(rows);
      setTimeout(() => {
        let newRow = this.getRows();
        // console.log(newRow);
        // this.params.api.updateRowData({ update: newRow });
        this.subject.publish(this.ctx, 'event:grid.update' + this.gridName, newRow);
      }, 500);

    }

  }

  // 抽屉
  openDrawer(params) {
    let formId = '';
    let title = '';
    let width = '38vw';
    let drawer;
    this.isLoading = true;

    if (params.hasOwnProperty('formId')) {
      formId = this.expressionService.evaluate(params.formId, {
        context: this.ctx,
        model: this.ctx['model'],
        data: this.data,
      });
      if (formId == null) formId = params.formId;

    } else {
      formId = this.expressionService.evaluate(params.api, {
        context: this.ctx,
        model: this.ctx['model'],
        data: this.data,
      });
      if (formId == null) formId = params.api;
    }

    if (params.hasOwnProperty('title')) {
      title = params.title;
    } else {
      title = params.name;
    }
    if (params.hasOwnProperty('width')) {
      width = params.width;
    }
    if (params.hasOwnProperty('link')) {
      this.ctx['link'] = params.link;
    }
    const data = {
      ...this.ctx.model, node: this.params.node['data'], link: this.ctx['link'],
      // conditionModel: { ...this.ctx.model, node: this.params.node['data'] },
    };
    if (params.hasOwnProperty('custom')) {
      if (params.custom == 'PlatformInquiry') {
        drawer = DrawerInquiryComponent;
      } else if (params.custom == 'VehicleMasterControl') {
        drawer = DrawerVehicleMasterControlComponent;
      }
    }

    const openDrawer = drawer ? drawer : ApesDrawerCustomGridComponent;

    const drawerRef = this.drawerService.create<DrawerVehicleMasterControlComponent, { formId: string, api: string, data: any }, string>({
      apesTitle: title,
      apesContent: openDrawer,
      apesWidth: width,
      apesContentParams: {
        formId: formId,
        api: params.api,
        data: data,
      },
    });
    drawerRef.afterOpen.subscribe(() => {
      this.isLoading = false;
      this.cd.detectChanges();
    });

    drawerRef.afterClose.subscribe(data => {
      this.isLoading = false;
      this.cd.detectChanges();
    });
  }

  // 打印
  openPrint(params) {
    let reportUrl;
    this.apiService.post('report.getUrl', {}).subscribe((body) => {
      if (exists(body)) {
        reportUrl = body;
        let reportName = params.report;
        let id;
        if (this.data.hasOwnProperty('ID')) {
          id = this.data['ID'];
        } else {
          id = this.data.id;
        }
        window.open(reportUrl + reportName + '&id=' + id);
      }
    });
  }

  // 确认
  openConfirm(params) {
    let callbackBody = this.apesConfig.callback;
    let node = { ...params };
    let style;
    if (params.hasOwnProperty('style')) {
      style = getO(params.style);
    } else {
      style = { textAlign: 'center' };
    }

    this.modalService.confirm({
      apesTitle: params.title,
      apesContent: params.content,
      apesBodyStyle: style,
      apesOkText: '确认',
      apesOkType: 'primary',
      apesOnOk: () => {
        this.expressionService.evaluate(callbackBody, {
          context: this.ctx,
          form: this.ctx['form'],
          model: this.ctx['model'],
          data: this.data,
          node: node,
        }, true);
      },
      apesCancelText: '取消',
      apesOnCancel: () => {
      },
    });

  }

  // 确认
  openButton(params) {
    let callbackBody = this.apesConfig.callback;
    let node = { ...params, rowIndex: this.rowIndex, event: this.event };
    this.isLoading = true;

    this.subject.subscribe(this.ctx, 'button_' + node.id + '_' + this.rowIndex, data => {
      this.isLoading = data.loading ? toBoolean(data.loading) : false;
      this.cd.detectChanges();
    });

    this.expressionService.evaluate(callbackBody, {
      context: this.ctx,
      form: this.ctx['form'],
      model: this.ctx['model'],
      data: this.data,
      node: node,
    }, true);

  }

  isShowDot(btn) {
    this.showDot = false;
    let showDot = false;
    if (btn.hasOwnProperty('showBadge')) {
      showDot = this.expressionService.evaluate(btn.showBadge, {
        context: this.ctx,
        model: this.ctx['model'],
        data: this.data,
      });
    }

    return showDot;
  }

  private getRows(): any[] {
    let rows = [];
    this.params.api.selectAll();
    this.params.api.getSelectedNodes().forEach((node) => {
      rows.push(node.data);
    });
    return rows;
  }

  private switchLink(data: any, method: string, params) {
    if (isObject(params)) Object.assign(data, params);
    if (method == null) {
      this.msg.error('该链接尚未存在，麻烦核实！', { 'apesDuration': 5000 });
      return false;
    }
    const formId = method;
    const url = '/' + formId;
    this.gridConfigService.setRouterData(data, formId);
    if (this.rs.exists(url) || this.rs.curUrl === url) {
      this.router.navigateByUrl(formId);
    } else {
      this.router.navigate([formId]);
    }
  }

  getTooltipFormatter(btn): string {
    let value = this.params.value;
    let expression = btn.tooltipFormatter || 'value';
    return this.expressionService.evaluate(expression, {
      context: this.ctx,
      model: this.ctx['model'],
      data: this.data,
      value: value,
    });
  }

  showHidden() {
    let showHidden = this.params.column['colDef'].showHidden;
    return showHidden;
  }

  showBtnStyle(btn) {
    let style;
    if (btn.hasOwnProperty('btnStyle')) {
      style = getO(btn.btnStyle);
    }
    return style;
  }

  showIconStyle(btn) {
    let style;
    if (btn.hasOwnProperty('iconStyle')) {
      style = getO(btn.iconStyle);
    }
    return style;
  }

  showBtnIconTheme(btn) {
    let theme = 'outline';
    if (btn.hasOwnProperty('iconTheme')) {
      let expression = btn.iconTheme;
      theme = this.expressionService.evaluate(expression, {
        context: this.ctx,
        model: this.ctx['model'],
        data: this.data,
      });
    }
    return theme;
  }

  checkShowBtn(params: BaseBtnFace) {
    let check = true;
    let btn = params.btn;
    if (btn.id) {
      if (params.type) {
        check = this.getButtonHide(btn.id, params.type);
      } else {
        check = this.getButtonHide(btn.id);
      }
    }

    if (check && this.hideBtnBar && !btn.hasOwnProperty('sum')) {
      check = false;
    }

    if (check && params.hasOwnProperty('showTooltip')) {
      if (btn.hasOwnProperty('tooltipFormatter')) {
        check = params.showTooltip;
      } else {
        check = !params.showTooltip;
      }
    }

    if (check && params.hasOwnProperty('showHidden')) {
      check = params.showHidden ? this.showHidden() : !this.showHidden();
    }

    if (check && params.hasOwnProperty('showDisabled')) {
      check = params.showDisabled ? btn.disabled : !btn.disabled;
    }

    return check;
  }

  checkBtnStatus(status) {
    return this.expressionService.evaluate(status, {
      context: this.ctx,
      model: this.ctx['model'],
      data: this.data,
    });
  }

}
